<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.util.Vector,com.ejoysoft.wlanyz.business.Carriers,com.ejoysoft.wlanyz.business.Task,com.ejoysoft.wlanyz.business.Ap,com.ejoysoft.wlanyz.business.Ac,com.ejoysoft.common.Constants,com.ejoysoft.common.exception.NoRightException" %>
<%@page import="sun.reflect.generics.tree.IntSignature"%>
<%@page import="com.ejoysoft.common.Format"%>
<%@ include file="../include/jsp/head.jsp"%>
<%

if(!globa.userSession.hasRight("10005"))
      throw new NoRightException("用户不具备操作该功能模块的权限，请与系统管理员联系！");
 
    //初始化
    Carriers  task0=null;
    Carriers obj=new Carriers(globa);
    //查询条件
    String  strCity=ParamUtil.getString(request,"strCity","").trim();
    String  strNetType=ParamUtil.getString(request,"strNetType","").trim();
    String  strStartTime=ParamUtil.getString(request,"strStartTime","").trim();
    String  strEndTime=ParamUtil.getString(request,"strEndTime","").trim();
   
    	//当前页
	int intCurPage= Integer.parseInt(ParamUtil.getString(request,"strCurPage","1"));
	String tWhere="";
	if (!strCity.equals("")) {
	  tWhere += " and wlan_resc_comunity.strCity LIKE '%" + strCity + "%'";
	}
	if (!strNetType.equals("")) {
	  tWhere += " and wlan_test_result.strNetType LIKE '%" + strNetType + "%'";
	}
	
	
	String checked1 =  ParamUtil.getString(request,"checkedFlag","all"); 
	if(checked1.equals("checked")){
	  tWhere += " and checkedLocation is not null and checkedLocation <>' ' ";
	}
	else if(checked1.equals("unchecked")){
	  tWhere += " and checkedLocation is null or checkedLocation =' '";
	}
	 tWhere += " ";

	//记录总数
	int intAllCount; 
	if(strCity.equals("")&&strNetType.equals("")&&strStartTime.equals("")&&strEndTime.equals(""))
	{ tWhere+=" where 1=1";
	  intAllCount=obj.getCount(tWhere);
	  }
	  else {
	  intAllCount=obj.getCount1(tWhere);
	  }	

	//每页记录数
	String strPageSize = ParamUtil.getString(request,"strPageSize","10");
    int intPageSize;
    if(strPageSize.equals("所有"))intPageSize = intAllCount;
      else  intPageSize = Integer.parseInt(strPageSize);
	//共有页数
 	int intPageCount=(intAllCount-1)/intPageSize+1;
	// 循环显示一页内的记录 开始序号
	int intStartNum=(intCurPage-1)*intPageSize+1;
	//结束序号
	int intEndNum=intCurPage*intPageSize;   
	//获取到当前页面的记录集
	Vector<Carriers> vctObj;
	if(strCity.equals("")&&strNetType.equals("")&&strStartTime.equals("")&&strEndTime.equals(""))
	{ 
	 vctObj=obj.list(tWhere,intStartNum,intPageSize);
	 }
	 else
	 { vctObj=obj.list2(tWhere,intStartNum,intPageSize,strStartTime,strEndTime);
	 }
	//获取当前页的记录条数
	int intVct=(vctObj!=null&&vctObj.size()>0?vctObj.size():0);
	
	String exportContent = ParamUtil.getString(request,"exportContent","");
		if(exportContent.equals("allPage"))
		{
			vctObj=obj.list(tWhere,0,0);
		}
   	   	StringBuffer sb = new StringBuffer("<html><body><table  border=1>");
	    sb.append("<tr><td>地市</td><td>区</td><td>热点名称</td><td>AP名称</td><td>运营商</td><td>任务名称</td><td>MAC</td><td>时限</td></tr>");
	   
	   if(vctObj!=null){
    
    	for (int i = 0;i < vctObj.size(); i++) {
    	
                  String strId = "";//结果id
                  String strApMac = "";//APMac
                  String strCarriers="";//运行商
                  String strTaskId=""; //任务Id
                  String strTaskName="";//任务名称
                  String time="";//任务时限
                  String strApName="";//AP名称
                  String hotpotid="";//热点Id
                  String city="";//地市
                  String town="";//区
                  String hotpotname="";//热点名称
                  String community="";//小区
                  Carriers obj1 = vctObj.get(i);
                  strId= Format.forbidNull(obj1.getStrId());
                  strApMac= Format.forbidNull(obj1.getStrApMac());//Mac
                  strCarriers= Format.forbidNull(obj1.getStrCarriers());//运行商
                  strTaskId = Format.forbidNull(obj1.getStrTaskId());
                  community= Format.forbidNull(obj1.getStrCommunityId());//小区ID
                  Task obj2=new Task(globa);
                  String where2= "where strTaskId = '" + strTaskId + "'";
                  Task vctObj2=obj2.show1(where2);
                  if(vctObj2==null)
                  {
                   strTaskName=" ";
                   time=" ";
                  }
                  else {
                  strTaskName= Format.forbidNull(vctObj2.getStrTaskName());//任务名称
                  if(vctObj2.getDtStartTime()!=null||vctObj2.getDtEndTime()!=null)time=vctObj2.getDtStartTime()+"———"+vctObj2.getDtEndTime();//时限
                  }
                  Ap obj3=new Ap(globa);
                  String where3= "where strMac_Addr = '" + strApMac + "'";
                  Ap vctObj3=obj3.show1(where3);
                  if(vctObj3==null)
                  {strApName =" ";
                  hotpotname=" ";
                  }
                   else
                   { strApName=  Format.forbidNull(vctObj3.getDevice_Name());//Ap名称
                  hotpotid =  Format.forbidNull(vctObj3.getStrHotSpot());
                  Ac obj4=new Ac(globa);
                  String where4= "where strId = '" + hotpotid + "'";
                  Ac vctObj4=obj4.show(where4); 
                  hotpotname= Format.forbidNull(vctObj4.getStrHotPotName());//热点名称
                  }
                  Carriers obj5=new Carriers(globa);
                  String where5= " where strCommId = '"+community + "'";
                   Carriers vctObj5=obj5.show3(where5); 
                   city=  Format.forbidNull(vctObj5.getStrcity1());
                   town = Format.forbidNull(vctObj5.getStrtown1());
                  
            	sb.append("<tr><td>"+(city==null?" ":city));
		       sb.append("</td><td>");
		       sb.append(town==null?" ":town);
		       sb.append("</td><td>");
		       sb.append(hotpotname==null?" ":hotpotname);
		       sb.append("</td><td>");
		       sb.append(strApName==null?" ":strApName);
		       sb.append("</td><td>");
		       sb.append(strCarriers==null?" ":strCarriers);
		       sb.append("</td><td>");
		       sb.append(strTaskName==null?" ":strTaskName);
		       sb.append("</td><td>");
		       sb.append(strApMac==null?" ":strApMac);
		       sb.append("</td><td>");
		       sb.append(time==null?" ":time);
		       sb.append("</td></tr>");
		        
		    }
	    } 
	     sb.append("</table></body></html>");
	    String strFileName = "运行商对比分析信息核查表.xls";//自定义csv文件的文件名
	    response.setContentType("APPLICATION/*");
	    response.setHeader( "Content-Disposition", "attachment;filename="  + new String( strFileName.getBytes("gbk"), "ISO8859-1" ));
	    out.clearBuffer(); 
	    out = pageContext.pushBody();
	    ServletOutputStream output = response.getOutputStream();
	    output.write(sb.toString().getBytes());
	    globa.closeCon();
	    
%>
<%@ include file="../include/jsp/footer.jsp"%>
